package com.ymatou.counter.api.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.counter.api.parameter.GetNaturalListMultiBean;
import com.ymatou.counter.api.service.GetNaturalListMultiCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取指定时间段内计数器 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetNaturalListMulti {
	private static GetNaturalListMultiBean getNaturalListMultiBean;
	private static GetNaturalListMultiCall getNaturalListMultiCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取指定时间段内计数器");
	}

	@Before
	public void caseUp() {
		getNaturalListMultiBean = new GetNaturalListMultiBean();
		getNaturalListMultiCall = new GetNaturalListMultiCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getNaturalListMultiCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNaturalListMulti_001() {
		Logger.start(true,"获取指定时间段内计数器");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, getNaturalListMultiCall.getMsg(), "验证Msg");
			Logger.verifyEquals(
					1,
					getNaturalListMultiCall.getData().getJSONObject(TargetId1)
							.get(YMTDateUtil.getSysTime("yyyy-MM-dd'T'00:00:00")), "验证TargetId1("+TargetId1+")的计数器的值");
			Logger.verifyEquals(
					3,
					getNaturalListMultiCall.getData().getJSONObject(TargetId2)
							.get(YMTDateUtil.getSysTime("yyyy-MM-dd'T'00:00:00")), "验证TargetId2("+TargetId2+")的计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalListMulti_002() {
		Logger.start(false,"不输入AppId,失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOAPPID_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalListMulti_003() {
		Logger.start(false,"不输入TargetId,失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTARGETIDS_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalListMulti_004() {
		Logger.start(false,"不输入Counter,失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOCOUNTER_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalListMulti_005() {
		Logger.start(false,"不输入开始时间，失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalListMulti_006() {
		Logger.start(false,"不输入结束时间，失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String startTime = YMTDateUtil.getBeforeOrNextDay(-1);
			getNaturalListMultiBean.setStartTime(startTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalListMulti_007() {
		Logger.start(false,"错误的AppId,失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("errorTest");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalListMulti_008() {
		Logger.start(false,"输入错误的Counter,失败");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("errorc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalListMulti_009() {
		Logger.start(false,"输入不存在的TargetId,没有查询出数据");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, getNaturalListMultiCall.getMsg(), "验证Msg");
			Logger.verifyEquals(
					4,
					getNaturalListMultiCall.getData().getJSONObject(TargetId1)
							.get(YMTDateUtil.getSysTime("yyyy-MM-dd'T'00:00:00")), "验证TargetId1("+TargetId1+")的计数器的值");
			Logger.verifyEquals(
					0,
					getNaturalListMultiCall.getData().getJSONObject(TargetId2)
						.get(YMTDateUtil.getSysTime("yyyy-MM-dd'T'00:00:00")), "验证TargetId2("+TargetId2+")的计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalListMulti_010() {
		Logger.start(false,"错误的开始时间");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = "aabbcc";
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalListMulti_011() {
		Logger.start(false,"错误的结束时间");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = "aabbcc";
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalListMulti_012() {
		Logger.start(false,"开始时间先于结束时间");
		try {
			String TargetId1 = TestDataManager.getRandomUUID().toString();
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			Logger.comment("给TargetId1为"+TargetId1 + ":添加计数器 c1: 1");
			new CounterCallService().setNatural("Test", "nc1", TargetId1, 1, 1);
			Logger.comment("给TargetId2为"+TargetId2 + ":添加计数器 c1: 3");
			new CounterCallService().setNatural("Test", "nc1", TargetId2, 1, 3);

			// 参数
			getNaturalListMultiBean.setAppId("Test");
			getNaturalListMultiBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1);
			getNaturalListMultiBean.setStartTime(StartTime);
			getNaturalListMultiBean.setEndTime(EndTime);
			String[] TargetIds = { TargetId1, TargetId2 };
			getNaturalListMultiBean.setTargetIds(TargetIds);
			getNaturalListMultiCall.setData(getNaturalListMultiBean);
			getNaturalListMultiCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListMultiCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListMultiCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}